package com.yike.user.service.impl;

import com.yike.user.entity.AgentCount;
import com.yike.user.mapper.AgentCountMapper;
import com.yike.user.service.AgentCountService;
import com.yike.user.param.AgentCountPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yike.common.base.BaseServiceImpl;
import com.yike.common.pagination.Paging;
import com.yike.common.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 代理商分佣统计 服务实现类
 *
 * @author Sakura
 * @since 2024-11-13
 */
@Slf4j
@Service
public class AgentCountServiceImpl extends BaseServiceImpl<AgentCountMapper, AgentCount> implements AgentCountService {

    @Autowired
    private AgentCountMapper agentCountMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveAgentCount(AgentCount agentCount) throws Exception {
        return super.save(agentCount);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateAgentCount(AgentCount agentCount) throws Exception {
        return super.updateById(agentCount);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteAgentCount(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<AgentCount> getAgentCountPageList(AgentCountPageParam agentCountPageParam) throws Exception {
        Page<AgentCount> page = new PageInfo<>(agentCountPageParam, OrderItem.desc(getLambdaColumn(AgentCount::getCreateTime)));
        LambdaQueryWrapper<AgentCount> wrapper = new LambdaQueryWrapper<>();
        IPage<AgentCount> iPage = agentCountMapper.selectPage(page, wrapper);
        return new Paging<AgentCount>(iPage);
    }

}
